package cn.holy.app.xcddt.ui.fragment

import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.HorizontalScrollView
import android.widget.ImageView
import cn.holy.app.xcddt.R
import cn.holy.app.xcddt.domain.RecordBean
import com.qmuiteam.qmui.widget.QMUIItemViewsAdapter
import com.zhy.adapter.recyclerview.CommonAdapter
import com.zhy.adapter.recyclerview.base.ViewHolder
import kotlinx.android.synthetic.main.fragment_list.*
import java.util.*

/**
 * Created by 69568 on 2018/2/24.
 */

class LocalRecordFragment : Fragment() {


    //    @Inject
    //    RecordRepository recordRepository;
    private var mRecordBeans: List<RecordBean>? = ArrayList()
    private var commonAdapter: CommonAdapter<RecordBean>? = null

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.fragment_list, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        //        App.ComponentHolder.getAppComponent().inject(this);
        initData()
    }

    private fun initData() {
        val layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)

        listview.layoutManager = layoutManager
        commonAdapter = object : CommonAdapter<RecordBean>(context, R.layout.layout_record_item, mRecordBeans) {

            override fun convert(holder: ViewHolder, recordBean: RecordBean, position: Int) {
                val photosList = holder.getView<HorizontalScrollView>(R.id.photo_list)

                object : QMUIItemViewsAdapter<String, View>(photosList) {

                    override fun createView(parentView: ViewGroup): View {
                        return LayoutInflater.from(context).inflate(R.layout.layout_photo_item_list, parentView, false)
                    }

                    override fun bind(item: String, view: View, position: Int) {
                       view.findViewById<ImageView>(R.id.iv_thumb)
                    }
                }

            }
        }
//        recordRepository.getLocalRecords().observe(this, Observer<List<RecordBean>> { recordBeans ->
//            mRecordBeans = recordBeans
//            commonAdapter!!.notifyDataSetChanged()
//        })

    }

}
